package com.liruo.learn.spring.mvc.controller.m1handlermapping;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.function.RequestPredicates;
import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.RouterFunctions;
import org.springframework.web.servlet.function.ServerRequest;
import org.springframework.web.servlet.function.ServerResponse;

/**
 * @Author:liruo
 * @Date:2023-10-05-21:24:19
 * @Desc
 */
@Configuration
public class RouterFunction1 {
  @Bean
  public RouterFunction<ServerResponse> routerFunctions(){
    return  RouterFunctions.nest(
        RequestPredicates.path("/RouterFunction"),
        RouterFunctions
            .route(RequestPredicates.GET("1"), this::f1)
            .andRoute(RequestPredicates.GET("2"), this::f2)
    );
  }
  public ServerResponse f1(ServerRequest req){
    return ServerResponse.ok()
        .body(getClass().getSimpleName() + "#f1");
  }
  public ServerResponse f2(ServerRequest req){
    return ServerResponse.ok()
        .body(getClass().getSimpleName() + "#f2");
  }
}
